<?php


namespace app\home\service;

use think\Config;

class PayFactory
{

    public static function factory($channel){
        // 严格判断是否为整数
        if(!is_numeric($channel) || strpos($channel,'.') !== false){
            return null;
        }
        $mapPayClass = Config::get('MapPayClass');
        $class = isset($mapPayClass[$channel])?$mapPayClass[$channel]:null;
        if(!$class){
            return null;
        }

        if(!isset($class['path'])){
            return null;
        }

        if(!isset($class['config'])){
            return null;
        }

        if(!class_exists($class['path'])){
            return null;
        }

        // 判断是否手动传入了回调地址 如果没有 就自动生成
        if(!isset($class['config']['notify_url'])){
            $class['config']['notify_url'] = 'https://pay.hemayouxi.cn/home/pay/notify?channel='.$channel;
        }

        return new $class['path']($class['config']);
    }
}